class HotPostType < ActiveRecord::Base
  
  def current_user_zhuis_count
    FollowHotPostSetting.count( 
      :conditions => [
        'hot_posts.hot_post_type_id = ? and follow_hot_post_settings.user_id = ? and follow_hot_post_settings.status = ? ',
        id,
        User.current_user.id,
        'zhui'
      ],
      :include => :hot_post
    )
  end
  
  def self.all_with_power
    power_up all(:order => 'created_at asc')
  end
  
  def self.power_up(types)
    def types.current_user_zhuis_count
      each_with_object({ :count => 0 }) do |type,hash|
        hash[:count] += type.current_user_zhuis_count                        
      end[:count]
    end
    def types.hot_posts_count
      each_with_object({ :count => 0 }) do |type,hash|
        hash[:count] += type.hot_posts_count
      end[:count]
    end
    types
  end
end
